﻿using MathWorks.MATLAB.NET.Arrays;
using mhyUnwrap;
//using mhyUnwrapNative;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

//using UnwrapNative;


namespace Util
{
    public  class Util
	{
		public static Util instance = new Util();
		/// <summary>
		/// 加载matlab环境
		/// </summary>
		public  void InitDll() 
		{
		
			unwrap = new myunwrap();
		}
	myunwrap unwrap ;
		public Array Unwrap(Array input, double tol = Math.PI, int dim = 1)
		{
			// 初始化 MATLAB 函数库
			if (unwrap == null)
			{
				unwrap = new myunwrap();
			}
			// 将输入数组转换为 MWNumericArray
			MWNumericArray p = new MWNumericArray(input);

			// 调用 MATLAB unwrapFunction 方法
			MWArray result;
			if (tol == Math.PI && dim == 1)
			{
				result = unwrap.Unwrap(p);
			}
			else if (dim == 1)
			{
				result = unwrap.Unwrap(p, tol);
			}
			else
			{
				result = unwrap.Unwrap(p, tol, dim);
			}

			// 将结果转换为 Array
			MWNumericArray mwResult = (MWNumericArray)result;
			Array unwrappedArray = mwResult.ToArray();

			return unwrappedArray;
		}
	}
}
